#!/usr/bin/env python3
#coding=utf8

import schedule
import time

from datetime import datetime

import pandas as pd
import uiautomator2 as u2
import time
import logging
import re
import json


pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)

# log设置
logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(funcName)s - %(message)s')
logger = logging.getLogger(__name__)

# 企业微信应用名
APP_PACKAGE_FULL_NAME = "com.tencent.wework"

# d.click_post_delay = 1.5#
# 手机adb设备 用 adb devices 查看
d = u2.connect('5ENDU19A23003621')# 
print(d.info)


def unlock_phone():
    # 点亮亮屏幕
    d.screen_on()
    # 上滑动屏幕
    d.swipe_points([(0.472, 0.875), (0.512, 0.495)], 0.05)
    # 6位数字密码解锁
    d(resourceId="com.android.systemui:id/key0").click()
    d(resourceId="com.android.systemui:id/key0").click()
    d(resourceId="com.android.systemui:id/key0").click()
    d(resourceId="com.android.systemui:id/key0").click()
    d(resourceId="com.android.systemui:id/key0").click()
    d(resourceId="com.android.systemui:id/key0").click()

def daka():
    # 启动企业微信
    d.app_start(APP_PACKAGE_FULL_NAME)
    d(text="打卡").click()
    d(resourceId="com.tencent.wework:id/m03").click() # 三个点点
    d(text="进入应用").click()
    d.click(0.5, 0.584)
    d.click(0.5, 0.584)
    # d(resourceId="com.tencent.wework:id/mw4").click()
    # d(resourceId="com.tencent.wework:id/bs9").click()
    # print(d(resourceId="com.tencent.wework:id/lw").get_text())
    # print(d(resourceId="com.tencent.wework:id/lyy").get_text())
    # print(d(resourceId="com.tencent.wework:id/bs9").get_text())

    print("完成执行")
    logger.info("打卡完成!")
    
    # d(resourceId="com.hexin.android.futures:id/leftImageView").click()
def job():
    # 1. 解锁手机
    unlock_phone()
    print(d.app_current())
    # 2. 执行打卡
    daka()

# schedule.every().minute.at(":30").do(job)
schedule.every().day.at("09:28").do(job)

# schedule.every(1).seconds.do(job)
# schedule.every(10).seconds.do(job)
# schedule.every(10).minutes.do(job)
# schedule.every().hour.do(job)
# schedule.every().day.at("10:30").do(job)
# schedule.every(5).to(10).minutes.do(job)
# schedule.every().monday.do(job)
# schedule.every().wednesday.at("13:15").do(job)
# schedule.every().minute.at(":17").do(job)
while True:
    schedule.run_pending()
    time.sleep(1)